<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let loginList = [{
            userName: 'admin',
            password: 'admin321'
        }, {
            userName: 'zhangsan',
            password: 'zs321'
        }, {
            userName: 'lisi',
            password: 'ls321'
        }, {
            userName: 'yyqx',
            password: 'yyqx321'
        }]
        let userInfo = {
            token1: {
                city: '杭州',
                money: '1000w',
                sex: '女',
                userName: 'admin',
                password: 'admin321'
            },
            token2: {
                city: '北京',
                money: '1100w',
                sex: '女',
                userName: 'zhangsan',
                password: 'zs321'
            },
            token3: {
                city: '北京',
                money: '800w',
                sex: '男',
                userName: 'lisi',
                password: 'ls321'
            },
            token4: {
                city: '天津',
                money: '600w',
                sex: '男',
                userName: 'yyqx',
                password: 'yyqx321'
            }
        }
        let login = function() {
            let uname = prompt('请输入账号')
            let upwd = prompt('请输入密码')
            for (let i = 0; i < loginList.length; i++) {
                if (uname === loginList[i].userName && upwd === loginList[i].password) {
                    let n = Math.floor(Math.random() * 4 + 1)
                    for (let k in userInfo) {
                        if (k === 'token' + n) {
                            alert(`登录成功，具体用户信息
                           city:${userInfo['token' + n].city}
                           money:${userInfo['token' + n].money}
                           sex:${userInfo['token' + n].sex}
                           username:${userInfo['token' + n].userName}`)
                            return
                        }

                    }
                    // alert(`登录成功，具体用户信息
                    //        city:${userInfo[n].city}
                    //        money:${userInfo[n].money}
                    //        sex:${userInfo[n].sex}
                    //        username:${userInfo[n].userName}`)

                    // return
                }
            }

            let registe = +prompt(`1.注册2.直接退出`)
            if (registe === 2) {
                return
            }
            if (registe === 1) {
                let obj = {}
                obj.userName = prompt(`请输入用户名`)
                obj.password = prompt(`请输入密码`)
                loginList.push(obj)
                console.log(loginList);
                alert('注册成功直接去登录')
                    //登录板块
                let uname2 = prompt('请输入账号')
                let upwd2 = prompt('请输入密码')
                for (let i = 0; i < loginList.length; i++) {
                    if (uname2 === loginList[i].userName && upwd2 === loginList[i].password) {
                        let n = Math.floor(Math.random() * 4 + 1)
                        for (let k in userInfo) {
                            if (k === 'token' + n) {
                                alert(`登录成功，具体用户信息
                           city:${userInfo['token' + n].city}
                           money:${userInfo['token' + n].money}
                           sex:${userInfo['token' + n].sex}
                           username:${uname2}`)
                                return
                            }

                        }
                    }

                }
                alert(`无机会，直接退出`)
                return
            }
        }
        login()
    </script>
</body>

</html>